package com.zimmur.app.mocolink.background.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.zimmur.app.mocolink.background.common.ReturnJsonEntity;
import com.zimmur.app.mocolink.background.common.StatusCodeEnum;
import com.zimmur.app.mocolink.domain.model.CommonQuestion;
import com.zimmur.app.mocolink.domain.model.Goods;
import com.zimmur.app.mocolink.domain.vo.TopicVo;
import com.zimmur.app.mocolink.service.ICommonQuestionService;
import com.zimmur.app.mocolink.service.IGoodsService;
import com.zimmur.app.mocolink.service.ITopicService;

@RestController
@RequestMapping("/html")
public class HtmlController extends BaseController{

	@Autowired
	private ITopicService topicService;
	@Autowired
	private ICommonQuestionService commonQuestionService;
	@Autowired
	private IGoodsService goodsService;
	
	@RequestMapping(value="/topicDetail",produces= MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
	public String topicDetail(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer topicId=getIntParam("topicId");
		TopicVo topicVo = topicService.selectTopicVoById(topicId);
		if(topicVo!=null){
			entity.setData(topicVo);
			codeEnum = StatusCodeEnum.CODE000000;
		}else{
			codeEnum = StatusCodeEnum.CODE400401;
		}
		entity.init(codeEnum);
		String callback = getRequest().getParameter("jsonpCallback");//客户端请求参数 
		String res;
		if(callback!=null && !"".equals(callback)){  
            res= callback+"("+JSONObject.toJSONString(entity)+")";  
        }else{  
            res= JSONObject.toJSONString(entity);  
        }  
		return res;
	}
	@RequestMapping(value="/helpCenter",produces= MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
	public String helpCenter(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		List<CommonQuestion> list = commonQuestionService.selectShowQuestion();
		if(list != null){
			entity.setData(list);
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		String callback = getRequest().getParameter("jsonpCallback");//客户端请求参数 
		String res;
		if(callback!=null && !"".equals(callback)){  
            res= callback+"("+JSONObject.toJSONString(entity)+")";  
        }else{  
            res= JSONObject.toJSONString(entity);  
        }  
		return res;
	}
	@RequestMapping(value="/goodsDetail",produces= MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
	public String goodsDetail(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		Integer goodsId=getParam("goodsId", 0);
		Goods goods = goodsService.selectById(goodsId);
		if(goods!=null){
			entity.setData(goods.getContent());
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		String callback = getRequest().getParameter("jsonpCallback");//客户端请求参数 
		String res;
		if(callback!=null && !"".equals(callback)){  
            res= callback+"("+JSONObject.toJSONString(entity)+")";  
        }else{  
            res= JSONObject.toJSONString(entity);  
        }  
		return res;
	}
	
}
